package net.sangpil.classes.utils.bitmap
{
	import flash.display.BitmapData;
	import flash.display.IBitmapDrawable;
	import flash.errors.IOError;
	import flash.geom.Rectangle;
	import flash.utils.ByteArray;
	
	public class GetBitmap
	{
		public static function getBitmap(src:IBitmapDrawable, width:Number, height:Number):BitmapData
		{
			var bitmapData:BitmapData = new BitmapData(width, height, true, 0x00000000);
			bitmapData.draw(src);
			return bitmapData;
		}
		
		public static function getBitmapSection(src:BitmapData, x:Number, y:Number, width:Number, height:Number):BitmapData
		{
 			var bitmapData:BitmapData = new BitmapData(width, height, true, 0x00000000);
 			var catchRect:Rectangle = new Rectangle(x, y, width, height);
			var pasteRect:Rectangle = new Rectangle(0, 0, width, height);
			var bytes:ByteArray = src.getPixels(catchRect);
			bytes.position = 0;
			try {
			    bitmapData.setPixels(pasteRect, bytes);
			}
			catch (e:IOError) {
			    trace(e); // output: ArgumentError: Error #2024: An object may not be added as a child of itself.
			}
			//bitmapData.setPixels(pasteRect, bytes);  
			return bitmapData;
		}
		
		public function GetBitmap()
		{
		}

	}
}